﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblDKLaiThuDAO
    {
        private DBService _db = null;
        public TblDKLaiThuDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable DKLaiThu_InsUp(TblDKLaiXe dklx, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblDangKyLaiThuXe_InsUp",
                    new string[] { "@ID", "@FulName", "@Address", "@PhoneMobile", "@SoBangLaiXeOto", "@LoaiXeMuonLaiThu", "@NgayDK", "@Hour","@Time", "@mode" }, 
                    new object[] { dklx.ID, dklx.FulName, dklx.Address, dklx.PhoneMobile, dklx.SoBangLaiXeOto, dklx.LoaiXeMuonLaiThu, dklx.NgayDK,
                               dklx.Hour, dklx.Time, mode }, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetAll()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from  TblDangKyLaiThuXe order by ID DESC ", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetDK_ByID( int ID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from  TblDangKyLaiThuXe where ID = @ID ", new string[]{ "@ID" }, new object[]{ ID }, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        //search

        public DataTable Search(string fullname, string phone)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblDKLaiXeThu_List",
                    new string[] { "@fullname", "@phone" }, new object[] { fullname, phone }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

    }
}
